package com.cloudfun.campusshare.controller;

import com.cloudfun.campusshare.common.constant.Code;
import com.cloudfun.campusshare.common.model.dto.DeviceModeSetCreateDTO;
import com.cloudfun.campusshare.common.model.dto.DeviceModeSetModifyDTO;
import com.cloudfun.campusshare.common.model.dto.DeviceModeSetSearchDTO;
import com.cloudfun.campusshare.common.model.vo.DeviceModeSetDetailVO;
import com.cloudfun.campusshare.common.model.vo.DeviceModeSetListVO;
import com.cloudfun.campusshare.common.model.vo.DeviceModeSetSimpleVO;
import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.response.BaseResultFactory;
import com.cloudfun.campusshare.common.response.PageResult;
import com.cloudfun.campusshare.common.security.AuthRequired;
import com.cloudfun.campusshare.service.DeviceModeSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by Huqin on 2020/5/11
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/v1/modeSet")
@Api(value = "模式集模块", description = "模式集模块")
@AuthRequired
public class DeviceModeSetController {

    @Autowired
    private DeviceModeSetService deviceModeSetService;


    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping
    public BaseResult<?> create(@ApiParam(value = "createDTO", required = true) @Validated({DeviceModeSetCreateDTO.Create.class}) @RequestBody DeviceModeSetCreateDTO createDTO) {
        deviceModeSetService.create(createDTO);
        return BaseResultFactory.produceEmptyResult(Code.SUCCESS);
    }

    @PutMapping
    @ApiOperation(value = "编辑", notes = "编辑")
    BaseResult<?> modify(@ApiParam(value = "modifyDTO", required = true) @Valid @RequestBody DeviceModeSetModifyDTO modifyDTO) {
        deviceModeSetService.modify(modifyDTO);
        return BaseResultFactory.produceEmptyResult(Code.SUCCESS);
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public BaseResult<PageResult<DeviceModeSetListVO>> querySchoolList(Pageable pageable, @ApiParam(value = "searchDTO") DeviceModeSetSearchDTO searchDTO) {
        return BaseResultFactory.produceResult(Code.SUCCESS, deviceModeSetService.search(pageable, searchDTO));
    }

    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public BaseResult<?> projectDelete(@ApiParam(value = "id", required = true) @RequestParam String id) {
        deviceModeSetService.delete(id);
        return BaseResultFactory.produceEmptyResult(Code.SUCCESS);
    }

    @ApiOperation(value = "详情", notes = "详情")
    @GetMapping("/detail")
    public BaseResult<DeviceModeSetDetailVO> detail(@ApiParam(value = "id", required = true) @RequestParam String id) {
        DeviceModeSetDetailVO res = deviceModeSetService.detail(id);
        return BaseResultFactory.produceResult(Code.SUCCESS, res);
    }

    @ApiOperation(value = "模式集简单列表", notes = "模式集简单列表")
    @GetMapping("/simpleList")
    public BaseResult<List<DeviceModeSetSimpleVO>> simpleList(@ApiParam(value = "searchDTO") DeviceModeSetSearchDTO searchDTO) {
        List<DeviceModeSetSimpleVO> roleList = deviceModeSetService.simpleList(searchDTO);
        return BaseResultFactory.produceResult(Code.SUCCESS, roleList);
    }
}
